package 网络编程多线程之聊天;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

/**
 * 
 * @author Administrator
 *
 */
public class Send implements Runnable {

	private DatagramSocket ds;
	public Send(DatagramSocket ds){
		this.ds = ds;
	}
	public void run() {
		
		try {
			//键盘输入数据
			BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
			String line = null;
			while((line = buff.readLine()) != null){
				if("886".equals(line))
					break;
				byte[] buf = line.getBytes();
				DatagramPacket dp = new DatagramPacket(buf, buf.length,InetAddress.getByName("192.168.1.255"),10002);
				ds.send(dp);
			}
		} catch (Exception e) {
			throw new RuntimeException("发送失败");
		}
	}

}
